package com.zs.myorm.framework.core.datasource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class JdbcDataSource extends AbstractDataSource {
	
	private String driver;
	private String url;
	private String user;
	private String password;

	public JdbcDataSource(Properties config) {
		init(config);
	}
	
	private void init(Properties config) {
		try {
			driver = (String) config.get("driver");
			url = (String) config.get("url");
			user = (String) config.get("user");
			password = (String) config.get("password");
			Class.forName(this.driver);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public Connection getConnection() throws SQLException {
		return DriverManager.getConnection(this.url, this.user, this.password);
	}

}
